package com.ssq.common;

import java.util.List;


public class Utils {

	/********************************
	 *******获取红球 蓝球      ********
	 *******************************/
	
	/**
	 * 上期期号
	 */
	public static String prevIssueNum(){
		String currentIssue = Config.getValue("currentIssue");;
		return minus(currentIssue, 1);
	}
	
	
	/**
	 * 追溯第n期期号
	 * @author fwb
	 * @param num 向前追溯的期数
	 */
	public static String PrevIssueNum(int num){
		String currentIssue = Config.getValue("currentIssue");
		return minus(currentIssue, num);
	}
	
	
	/**
	 * 上期期号,带当期期号参数
	 * @param issueNum 指定的期号 例如 09086
	 */
	public static  String prevIssueNum(String issueNum){
		String currentIssue = Config.getValue(issueNum);
		return minus(currentIssue, 1);
	}
	
	
	/**
	 * 追溯第n期期号,带当期期号参数
	 * @author fwb
	 * @param issueNum 指定的期号 例如 09086
	 * @param num 后退期数 
	 */
	public static String PrevIssueNum(String issueNum,int num){
		String currentIssue = Config.getValue(issueNum);
		return minus(currentIssue, num);
	}
	
	
	/**
	 * 获取上期篮球
	 * @param issueNum 指定的期号 例如 09086
	 */
	public static int getPrevBuleBall(){
		return Integer.parseInt(Config.getValue(prevIssueNum()).split("\\u007C")[1]);
	}
	
	
	/**
	 * 获取上期红球
	 */
	public static int[] getPrevRedBalls(){
		String[] redArray = Config.getValue(prevIssueNum()).split("\\u007C")[0].split(",");
		int[] redInt = new int[redArray.length];
		for (int i = 0; i < redArray.length; i++) {
			redInt[i] = Integer.parseInt(redArray[i]);
		}
		return redInt;
	}
	
	/**
	 * 根据期号获取篮球
	 * @param issueNum 指定的期号 例如 09086
	 */
	public static  int getBuleBall(String issueNum){
		return Integer.parseInt(Config.getValue(issueNum).split("\\u007C")[1]);
	}
	
	/**
	 * 根据期号获取红球
	 */
	public static  int[] getRedBalls(String issueNum){
		String[] redArray = Config.getValue(issueNum).split("\\u007C")[0].split(",");
		int[] redInt = new int[redArray.length];
		for (int i = 0; i < redArray.length; i++) {
			redInt[i] = Integer.parseInt(redArray[i]);
		}
		return redInt;
	}
	
	/**
	 * 期号相减
	 * @return String
	 */
	public static String minus(String currentIssue,int num) {
		if (num<=0) {
			num = 0;
		}
		return "0"+(Integer.parseInt(currentIssue)-num);
	}

	/**
	 * 期号相加
	 * @return String
	 */
	public static String plus(String currentIssue,int num) {
		if (num<=0) {
			num = 0;
		}
		//System.out.println("currentIssue>>"+currentIssue);
		return "0"+(Integer.parseInt(currentIssue)+num);
	}
	
	/**
	 * arrayList 转化为数组
	 */
	public static int[] tranferToArray(List<Integer> list){
		int num = list.size();
		int[] selectNum = new int[num];	
		for (int i = 0; i < num; i++) {
			selectNum[i] = list.get(i);
		}
		return selectNum;
	}
}
